﻿using Design.Common.Utils;

namespace SingletonPattern
{


    internal sealed class LazybonesInterlockSingleton
    {
        private static LazybonesInterlockSingleton _instance = null;
        private const string _name = "懒汉模式_Interlock";

        private LazybonesInterlockSingleton()
        {
            ConsoleExpansion.WriteLine($"{_name} 创建实例:{Guid.NewGuid()}");
        }

        public static LazybonesInterlockSingleton Instance
        {
            get
            {
                ConsoleExpansion.WriteLine($"{_name} 获取实例 is null {_instance == null}");

                Interlocked.CompareExchange(ref _instance, new LazybonesInterlockSingleton(), null);
                return _instance;
            }
        }
    }
}